package org.example.struct.array;

import java.util.Arrays;

/**
 * @author liyishan
 * @date 2023/8/9 11:13
 * @apiNote
 */

public class Test00724PivotIndex {
    public static void main(String[] args) {
        int[] nums = {1, 7, 3, 6, 5, 6};
        System.out.println(test(nums));
    }

    public static int test(int[] nums) {
        int left = 0;
        int sum = Arrays.stream(nums).sum();
        for(int i = 0 ; i<nums.length;i++){
            if(left == sum - nums[i]){
                return i;
            }else{
                left += nums[i];
                sum = sum - nums[i];
            }
        }
        return -1;
    }
}
